/**
 * 钱包页面
 * author wim
 */
import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:flutter/services.dart';
import 'package:flutter_aygsh/http/Api.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_aygsh/base/Constant.dart';
import '../../util/AppSaveInfoUtil.dart';
import '../../http/HttpUtil.dart';
import '../../util/SignUtil.dart';
class MyWalletPage extends StatefulWidget {
  MyWalletPage({Key key}) : super(key: key);

  @override
  _MyWalletPageState createState() => _MyWalletPageState();
}

class _MyWalletPageState extends State<MyWalletPage> {
  List<Color> colors = new List();
  String money = '0';
// String balance = "0";
  String token = "";
  @override
  Widget build(BuildContext context) {
    //
    return new Scaffold(
      appBar: new AppBar(
        title: Text('我的钱包',
            style: TextStyle(
                fontSize: ScreenUtil.getInstance().setSp(BIG_FONT_SIZE),
                color: Colors.black)),
        backgroundColor: Colors.white,
        brightness: Brightness.light,
        centerTitle: true,
        iconTheme: new IconThemeData(color: Colors.black),
        elevation: 0.5,
      ),
      body: AnnotatedRegion<SystemUiOverlayStyle>(
          value: SystemUiOverlayStyle.light,
          child: Container(
              width: ScreenUtil.getInstance().setWidth(750) - 2 * kMargin20,
              height: (ScreenUtil.getInstance().setWidth(750) - 2 * kMargin20) * 0.5,
              decoration: BoxDecoration(
                  image: DecorationImage(
                      image: AssetImage('images/wollet_bg.png'),
                      fit: BoxFit.fill)),
              margin: EdgeInsets.all(kMargin20),
              child: Container(
                padding: EdgeInsets.all(kMargin30),
                child: Column(
                  children: <Widget>[
                    Row(
                      children: <Widget>[
                        Text(
                          '我的余额(元)',
                          style: TextStyle(
                              fontSize:
                                  ScreenUtil.getInstance().setSp(BIG_FONT_SIZE),
                              color: hexToColor('#6f4e2c')),
                        )
                      ],
                    ),
                    Row(
                      children: <Widget>[
                        Expanded(
                          child: Text(
                            money,
                            style: TextStyle(
                                fontSize: ScreenUtil.getInstance()
                                    .setSp(BIG_FONT_SIZE * 1.5),
                                color: hexToColor('#6f4e2c')),
                          ),
                        ),
                        RaisedButton(
                          child: Text('账单明细',
                              style: TextStyle(
                                fontSize: ScreenUtil.getInstance()
                                    .setSp(SMALL_FONT_SIZE),
                              )),
                          textColor: hexToColor('#6f4e2c'),
                          // elevation: 20,
                          shape: RoundedRectangleBorder(
                              borderRadius: BorderRadius.circular(20)),
                          color: Color.fromRGBO(255, 255, 255, 1),
                          onPressed: () {
                            
                          },
                        ),
                      ],
                    ),
                    Container(
                      height: (ScreenUtil.getInstance().setWidth(750) - 2 * kMargin20) * 0.15,
                    ),
                    Row(
                      children: <Widget>[
                        Expanded(
                            flex: 1,
                            child:GestureDetector(
                              child: Container(
                                margin: EdgeInsets.only(left: kMargin20),
                                child: Row(
                                  children: <Widget>[
                                    Image.asset('images/chongzhi.png'),
                                    Text('充值',
                                        style: TextStyle(
                                            fontSize: ScreenUtil.getInstance()
                                                .setSp(BIG_FONT_SIZE),
                                            color: hexToColor('#6f4e2c')))
                                  ],
                                ))
                            ) ),
                        Container(
                            margin: EdgeInsets.all(kMargin10),
                            width: 1,
                            height: kMargin20,
                            color: hexToColor('#6f4e2c')),
                        Expanded(
                            flex: 1,
                            child:GestureDetector(
                              onTap: (){

                              },
                              child: Container(
                                margin: EdgeInsets.only(left: kMargin20),
                                child: Row(
                              children: <Widget>[
                                Image.asset('images/chongzhi.png'),
                                Text('提现',
                                    style: TextStyle(
                                        fontSize: ScreenUtil.getInstance()
                                            .setSp(BIG_FONT_SIZE),
                                        color: hexToColor('#6f4e2c')))
                              ],
                            ))
                            ) )
                      ],
                    )
                  ],
                ),
              ))),
    );
  }
 @override
  void initState() {
    super.initState();
    getString(TOKEN).then((value) {
        token = value;
        getUserInfo();
      });
  }

  getUserInfo() async {
    Map map = new Map();
    map['token'] = token;
    map['sign_type'] = createSignType(Api.URL_USER_GETMSG);
    print(map);
    Response<String> response =
        await HttpUtil().post(Api.URL_USER_GETMSG, data: getSign(map));
    Map userMap = json.decode(response.data);
    if (userMap['code'] == 1 && mounted) {
      setState(() {
        userMap = userMap['data'];
        money = userMap['user_msg']['balance'];
      });
    }
  }
}
